import type { App } from 'vue';
import { createRouter, createWebHashHistory } from "vue-router";

export const LAYOUT = () => import('/@/layout/index.vue');


/**
 * hidden                 是否在底部一级菜单中，底部 tabbar
 * isShowTabbar           是否显示底部 tabbar, true 不显示
 * isShowHead             是否显示头部 navbar
 * isActive               当前路由页面
 * back                   是否显示返回按钮
 * keepAlive              是否缓存该页面
 * icon                   显示 tabbar 上 icon
 * title                  页面名称
 */

const routes = [
    {
        path: "/main",
        name: "Home",
        component: LAYOUT,
        redirect: '/main/Home',
        isActive: false, // 是否选中当前 tabbar
        meta: {
            title: "首页",
            icon: 'home-4-fill',
            keepAlive: true,
            isShowHead: false, // 是否显示头
        },
        children: [
            {
                path: 'Home',
                name: 'Home',
                component: () => import('/@/views/Home/index.vue'),
                meta: {
                    keepAlive: true,
                    title: '首页',
                },
            },
        ],
    },
    {
        path: "/list",
        name: "list",
        component: LAYOUT,
        redirect: '/list/order',
        isActive: false,
        meta: {
            icon: 'file-list-3-fill',
            isShowHead: false, // 是否显示头
            title: "工单"
        },
        children: [
            {
                path: 'order',
                name: 'order',
                component: () => import('/@/views/order/index.vue'),
                meta: {
                    title: '工单',
                },
            }, {
                path: 'active',
                name: 'active',
                component: () => import('/@/views/order/active/active.vue'),
                meta: {
                    title: '工单详情',
                    back: true,
                    isShowTabbar: true,
                    isShowHead: true, // 是否显示头
                },
            },
        ],
    },
    {
        path: "/add",
        name: "add",
        component: LAYOUT,
        redirect: '/add/update',
        isActive: false,
        meta: {
            icon: 'contacts-book-upload-fill',
            isShowHead: false, // 是否显示头
            isShowTabbar: true,
            title: "上报",
        },
        children: [
            {
                path: 'update',
                name: 'update',
                component: () => import('/@/views/update/index.vue'),
                meta: {
                    title: '上报',
                },
            },
        ],
    },
    {
        path: "/site",
        name: "site",
        component: LAYOUT,
        redirect: '/site/check',
        isActive: false,
        meta: {
            icon: 'road-map-fill',
            isShowHead: false, // 是否显示头
            title: "巡检",
            keepAlive: true
        },
        children: [
            {
                path: 'check',
                name: 'check',
                component: () => import('/@/views/check/index.vue'),
                meta: {
                    keepAlive: true,
                    title: '巡检',
                },
            }, {
                path: 'siteMap',
                name: 'site',
                component: () => import('/@/views/check/modules/site.vue'),
                meta: {
                    keepAlive: true,
                    isShowHead: false, // 是否显示头
                    isShowTabbar: true,
                    title: '巡检地图',
                },
            },
        ],
    },
    {
        path: "/mine",
        name: "mine",
        component: LAYOUT,
        redirect: '/mine/my',
        isActive: false,
        meta: {
            icon: 'user-3-fill',
            isShowHead: true, // 是否显示头
            title: "我的",
        },
        children: [
            {
                path: 'my',
                name: 'my',
                component: () => import('/@/views/my/index.vue'),
                meta: {
                    title: '我的',
                },
            },
        ],
    },
    {
        path: "/msg",
        name: "msg",
        component: LAYOUT,
        redirect: '/msg/message',
        hidden: true, // 是否在底部一级菜单中
        meta: {
            icon: 'user-3-fill',
            back: true,
            isShowHead: true, // 是否显示头
            isShowTabbar: true,
            title: "我的消息",
        },
        children: [
            {
                path: 'message',
                name: 'message',
                component: () => import('/@/views/message/index.vue'),
                meta: {
                    title: '我的消息',
                },
            },
        ],
    },
    {
        path: "/search",
        name: "Search",
        hidden: true,
        meta: {
            title: "Search",
        },
        component: () => import("/@/components/search/components/component.vue"),
    },
    {
        path: "/login",
        name: "Login",
        hidden: true,
        meta: {
            title: "登录",
        },
        component: () => import("/@/views/Login/index.vue"),
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes: routes
});

// config router
export function setupRouter(app: App<Element>) {
    app.use(router);
}

export default router;